home *** CD-ROM | disk | FTP | other *** search
/ Transactor / Transactor_20_1987_Transactor_Publishing.d64 / common code.pal (.txt) < prev    next >
Commodore BASIC  |  2023-02-26  |  11KB  |  415 lines

  1. 1000 rem save"0:common code.pal",8
  2. 1010 open 8,8,8,"0:common code,p,w
  3. 1020 [158]700
  4. 1030 .opt o8
  5. 1040 ; [172] comm[145] code by jack r. farrah
  6. 1050 ;program [164] find identical code sequences
  7. 1060 ;in machine language programs [129] use
  8. 1070 ;as [185]sible subroutines.
  9. 1080 ;tested program [164] be in mem[176]y.
  10. 1090 ;all user [133]s in hex.
  11. 1100 ;screen [176] [153]er output.
  12. 1110 ;space bar pauses [155]ing.
  13. 1120 ; [172] c[145]s[192]ts [172]
  14. 1130 chrin [178] $ffcf ;[161] mult. char.[133]
  15. 1140 chrout [178] $ffd2 ;[153] [164] device
  16. 1150 [161]in [178] $ffe4 ;[161] [191]gle char.
  17. 1160 stadd [178] $fb ;start address
  18. 1170 ckadd [178] $fd ;check address
  19. 1180 setlfs [178] $ffba ;set [188]. file
  20. 1190 setnam [178] $ffbd ;name file
  21. 1200 [159] [178] $ffc0 ;[159] file
  22. 1210 [160] [178] $ffc3 ;[160] file
  23. 1220 chkout [178] $ffc9 ;set output file
  24. 1230 [156]chn [178] $ffcc ;[140] [150]aults
  25. 1240 [172][178]$0801 ;2049
  26. 1250 .w[176]d twobrk ;[129]ward po[181]er
  27. 1260 .byte 10,0 ;line number
  28. 1270 .byte $9e ;"sys" keyw[176]d [164]ken
  29. 1280 .[198] "2061" ;[158] address
  30. 1290 brk
  31. 1300 twobrk .w[176]d 0
  32. 1310 lda #147 ;clear screen
  33. 1320 jsr chrout
  34. 1330 begin ldx #0
  35. 1340 stx inflg ;clear flags
  36. 1350 stx mtchflg
  37. 1360 ;[172][161] user start address[172]
  38. 1370 titl lda title,x ;[153] prog. name
  39. 1380 beq start ;[175] start add.
  40. 1390 jsr chrout ;[133] message
  41. 1400 inx
  42. 1410 bne titl
  43. 1420 start ldx #0 ;set index
  44. 1430 jsr cr[145] ;blink curs[176]
  45. 1440 jsr [161] ;[161] address
  46. 1450 check cpx #5 ;">4 characters?
  47. 1460 bcs error ;only want 4
  48. 1470 ck1 dex  ;reset for cr counted
  49. 1480 cpx #255 ;only after 4
  50. 1490 beq convert ;make binary
  51. 1500 lda hxadd,x ;get hex ascii
  52. 1510 jsr eval ;check if valid
  53. 1520 bcc ck1 ;ok.get next char.
  54. 1530 ;*error message loop*
  55. 1540 error lda #$0d ;cr
  56. 1550 jsr chrout
  57. 1560 jsr crof ;turn off cursor
  58. 1570 ldx #0
  59. 1580 er1 lda ermess,x ;print error message
  60. 1590 beq begin ;start over
  61. 1600 jsr chrout
  62. 1610 inx
  63. 1620 bne er1
  64. 1630 ;*change ascii hex to binary & store
  65. 1640 convert ldx #0 ;set index
  66. 1650 jsr crof ;unblink cursor
  67. 1660 loop lda hxadd,x ;get ascii
  68. 1670 jsr makbi ;make binary
  69. 1680 asl  ;shift value into
  70. 1690 asl  ;high nybble position
  71. 1700 asl
  72. 1710 asl
  73. 1720 sta hxadd,x ;save it
  74. 1730 inx  ;raise index
  75. 1740 lda hxadd,x ;get next ascii
  76. 1750 jsr makbi ;make binary
  77. 1760 cpx #3 ;"4th character?
  78. 1770 beq over ;yes. finish here
  79. 1780 clc  ;no
  80. 1790 adc hxadd ;add [164] high nybble
  81. 1800 sta hxadd ;[148] combined [197]ue
  82. 1810 inx  ;raise index
  83. 1820 bne loop ;always branch
  84. 1830 over clc  ;add low nybble of
  85. 1840 adc hxadd[170]2 ;low byte [164] high
  86. 1850 sta hxadd[170]2 ;[175] [148] it
  87. 1860 [128] lda inflg ;"done end address?
  88. 1870 bne output ;yes.flag set
  89. 1880 lda hxadd ;no.save start add.
  90. 1890 sta stadd+1 ;on zero page
  91. 1900 lda hxadd+2
  92. 1910 sta stadd
  93. 1920 lda #$0d ;cr
  94. 1930 jsr chrout
  95. 1940 sta inflg ;set flag
  96. 1950 ;*get user end address*
  97. 1960 ldx #0 ;clear index
  98. 1970 end1 lda endmess,x ;print message
  99. 1980 beq next
  100. 1990 jsr chrout
  101. 2000 inx
  102. 2010 bne end1
  103. 2020 next ldx #0 ;clear for char. count
  104. 2030 jsr cron ;blink cursor
  105. 2040 jsr get ;get the address
  106. 2050 jmp check ;check &make binary
  107. 2060 output lda hxadd ;get binary end add.
  108. 2070 sta enck+1 ;and store in zero page
  109. 2080 lda hxadd+2
  110. 2090 sta enck
  111. 2100 lda #$0d ;cr
  112. 2110 jsr chrout
  113. 2120 ;*get output destination from user*
  114. 2130 ldx #0
  115. 2140 out1 lda outmess,x ;print message
  116. 2150 beq getit
  117. 2160 jsr chrout
  118. 2170 inx
  119. 2180 bne out1
  120. 2190 getit jsr getin ;get 's' or 'p'
  121. 2200 beq getit ;wait for key
  122. 2210 cmp #80 ;"p?
  123. 2220 beq [153] ;yes. [159] [153]er
  124. 2230 cmp #83 ;"no. s?
  125. 2240 bne getit ;no.(NULL) back for key
  126. 2250 beq byte ;screen output
  127. 2260 print jsr prout ;open printer file
  128. 2270 ;*get byte lgth. from user*
  129. 2280 byte ldx #0
  130. 2290 bytlup lda bytmess,x ;print message
  131. 2300 beq gtbyt
  132. 2310 jsr chrout
  133. 2320 inx
  134. 2330 bne bytlup
  135. 2340 erjmp jmp error ;out of range avoider
  136. 2350 gtbyt jsr cron ;blink cursor
  137. 2360 gt2 jsr getin ;get key
  138. 2370 beq gt2 ;wait for key
  139. 2380 cmp #$0d ;"cr?
  140. 2390 beq set[128] ;[150]ault selected
  141. 2400 jsr chrout ;[162] [197]ue. [153] it
  142. 2410 jsr e[197] ;check range
  143. 2420 jsr makbi ;make binary
  144. 2430 asl  ;sh[139]t [164] hi nybble
  145. 2440 asl
  146. 2450 asl
  147. 2460 asl
  148. 2470 sta hldr ;[148] it
  149. 2480 gt1 jsr [161]in ;[161] sec[145]d char.
  150. 2490 beq gt1 ;[146] [129] it
  151. 2500 jsr chrout ;[153] iit
  152. 2510 jsr e[197] ;check range
  153. 2520 jsr makbi ;make binary
  154. 2530 clc  ;add [164] hi nybble
  155. 2540 adc hldr
  156. 2550 cmp #2 ;">1?
  157. 2560 bcc erjmp ;<2 not allowed
  158. 2570 sta ckbyt ;store new value
  159. 2580 lda #$0d ;cr
  160. 2590 jsr chrout
  161. 2600 ;*calculate end addresses*
  162. 2610 setend jsr crof ;unblink cursor
  163. 2620 lda #$0d ;cr
  164. 2630 jsr chrout
  165. 2640 lda ckbyt ;get lgth. to check
  166. 2650 sec
  167. 2660 sbc #2 ;subtract 2
  168. 2670 sta hldr ;temporary save
  169. 2680 lda enck ;low byte end add.
  170. 2690 sec
  171. 2700 sbc hldr ;subtract value
  172. 2710 sta enck ;save new value
  173. 2720 bcc subhi ;reduce hi byte
  174. 2730 set1 lda enck ;get new end add.
  175. 2740 sec
  176. 2750 sbc ckbyt ;subtract byte lgth
  177. 2760 sta mtchck ;save as check value
  178. 2770 bcc sub2 ;reduce hi byte
  179. 2780 lda enck+1 ;get hi byte new end
  180. 2790 set2 sta mtchck+1 ;make same here
  181. 2800 set3 lda stadd ;start add. low byte
  182. 2810 clc
  183. 2820 adc ckbyt ;add byte lgth
  184. 2830 sta ckadd ;check pointer
  185. 2840 lda stadd+1 ;hi byte
  186. 2850 adc #0 ;add carry
  187. 2860 sta ckadd+1 ;put in pointer
  188. 2870 jmp main ;start main loop
  189. 2880 subhi dec enck+1
  190. 2890 jmp set1
  191. 2900 sub2 lda enck+1
  192. 2910 sbc #1
  193. 2920 jmp set2
  194. 2930 ;*main progam loop*
  195. 2940 main ldy #0 ;clear for ind.add.mode
  196. 2950 lda (stadd),y ;get value at start
  197. 2960 cmp (ckadd),y ;next to check
  198. 2970 beq (NULL)tmtch ;they match.check more.
  199. 2980 ma1 clc  ;no match
  200. 2990 lda ckadd ;add 1 to check add.
  201. 3000 adc #1
  202. 3010 sta ckadd ;store back
  203. 3020 lda ckadd+1 ;fix high byte
  204. 3030 adc #0
  205. 3040 sta ckadd+1 ;store
  206. 3050 lda ckadd ;have we reached
  207. 3060 cmp enck ;"end of possible bytes?
  208. 3070 bne main ;no.start [130] series
  209. 3080 lda ckadd[170]1 ;lo bytes matched
  210. 3090 cmp enck[170]1 ;"hi bytes same?
  211. 3100 bne main ;no.continue
  212. 3110 clc  ;done with this series
  213. 3120 lda stadd ;move start pointer
  214. 3130 adc #1 ;to next highest byte
  215. 3140 sta stadd ;store it
  216. 3150 lda stadd+1 ;fix hi byte
  217. 3160 adc #0
  218. 3170 sta stadd+1
  219. 3180 ldx #0 ;clear flag to show print
  220. 3190 stx mtchflg ;routine this is new add.
  221. 3200 lda stadd ;compare start add.
  222. 3210 cmp mtchck ;with last checkable byte
  223. 3220 bne return ;no match low byte
  224. 3230 lda stadd+1 ;check hi byte
  225. 3240 cmp mtchck+1
  226. 3250 bne return ;no match
  227. 3260 jmp exit ;all done, close up
  228. 3270 return jmp set3 ;out of range avoider
  229. 3280 ;*check remaining bytes for match*
  230. 3290 (NULL)tmtch ldx #0 ;clear indices
  231. 3300 ldy #0
  232. 3310 lup inx  ;x counts bytes matched
  233. 3320 cpx ckbyt ;"checked all?
  234. 3330 beq prnt ;yes.[153] 'em
  235. 3340 iny  ;no.index [164] [130] byte
  236. 3350 lda (stadd),y ;[161] [130] from start
  237. 3360 cmp (ckadd),y ;check [129] equality
  238. 3370 beq lup ;matches.[161] a[168]her
  239. 3380 jmp ma1 ;no match.move up a byte
  240. 3390 ;[172]here [139] all bytes match[172]
  241. 3400 prnt lda mtchflg ;"printed this stadd?
  242. 3410 beq prst ;no, so print it
  243. 3420 prnt1 jsr wait ;check for space bar
  244. 3430 lda #32 ;indent 2 spaces
  245. 3440 jsr chrout
  246. 3450 jsr chrout
  247. 3460 lda #36 ;$
  248. 3470 jsr chrout
  249. 3480 ldy #0 ;set upto get 2 bytes
  250. 3490 mr2 cpy #2
  251. 3500 beq mr1
  252. 3510 lda ckadd,y ;get add. of matching bytes
  253. 3520 sta hldr,y ;store for conversion
  254. 3530 iny  ;get 2nd byte
  255. 3540 bne mr2 ;always branch
  256. 3550 mr1 jsr prnthx ;convert and print add.
  257. 3560 jmp ma1 ;reset ckadd and loop again
  258. 3570 ;*print start address matched*
  259. 3580 prst lda #$0d ;cr
  260. 3590 jsr chrout
  261. 3600 lda #36 ;$
  262. 3610 jsr chrout
  263. 3620 ldy #0 ;set to get 2 bytes
  264. 3630 pr2 cpy #2
  265. 3640 beq pr1
  266. 3650 lda stadd,y ;get 1st byte
  267. 3660 sta hldr,y ;save for conversion
  268. 3670 iny  ;set for next byte
  269. 3680 bne pr2
  270. 3690 pr1 jsr prnthx ;convert and print
  271. 3700 lda #1 ;set flag to show
  272. 3710 sta mtchflg ;stadd was printed
  273. 3720 jmp prnt1 ;(NULL) print ckadd
  274. 3730 ;*text*
  275. 3740 title .byte $20,$20,$20,$12
  276. 3750 .asc "common code" :.byte $92,$0d,$0d
  277. 3760 .asc "start address in hex ": .byte $0d,$00
  278. 3770 ermess .asc "input error":.byte $0d,$00
  279. 3780 endmess .asc "end address in hex ":.byte $0d,$00
  280. 3790 outmess .asc "output to ": .byte $12
  281. 3800 .asc "s": .byte $92
  282. 3810 .asc "creen or ":.byte $12
  283. 3820 .asc "p": .byte $92
  284. 3830 .asc "rinter" :.byte $0d,$00
  285. 3840 bytmess .asc "byte length in hex":.byte $0d,$37,$9d,$00
  286. 3850 ;*subroutines*
  287. 3860 get jsr chrin ;get user input
  288. 3870 cmp #$0d ;"cr?
  289. 3880 beq d[145]e ;yes.exit routine
  290. 3890 sta hxadd,x ;s[164]re [198]ii char.
  291. 3900 inx  ;raise idex [129] [130]
  292. 3910 bne [161] ;[203] [161] it
  293. 3920 d[145]e rts
  294. 3930 ;[172]make 1 byte [198]ii in a binary[172]
  295. 3940 makbi cmp #58 ;"=>9?
  296. 3950 bcs let ;yes, its a letter
  297. 3960 sec  ;no so subtract 48
  298. 3970 sbc #48 ;for equiv. number
  299. 3980 rts  ;return
  300. 3990 let sec  ;for a to f
  301. 4000 sbc #55 ;subtract 55
  302. 4010 rts
  303. 4020 ;*check if valid hex ascii*
  304. 4030 eval cmp #71 ;"=>g?
  305. 4040 bcs bad ;yes, no [203]od
  306. 4050 cmp #65 ;"its < g.is it =>a?
  307. 4060 bcs (NULL)od ;yes, its valid
  308. 4070 cmp #58 ;"its <a.is it =>:?
  309. 4080 bcs bad ;yes.no [203]od
  310. 4090 cmp #48 ;"<:.is it <0?
  311. 4100 bcc bad ;yes. no (NULL)od
  312. 4110 (NULL)od clc  ;range ok.
  313. 4120 rts  ;back to caller
  314. 4130 bad pla  ;invalid.pull return
  315. 4140 pla  ;add. from stack
  316. 4150 jmp error ;user restart
  317. 4160 ;*set up printer file*
  318. 4170 prout lda #7 ;file #
  319. 4180 ldx #4 ;device
  320. 4190 ldy #$ff ;bogus second. add.
  321. 4200 jsr setlfs ;define the file
  322. 4210 lda #00 ;no name, no length
  323. 4220 jsr setnam ;required call
  324. 4230 jsr open ;open file 7
  325. 4240 ldx #7 ;set file 7 for output
  326. 4250 jsr chkout
  327. 4260 rts  ;back to caller
  328. 4270 ;*check/accept space bar pause*
  329. 4280 wait lda #0 ;clear flag to show
  330. 4290 sta inflg ;we're not waiting
  331. 4300 wa2 lda $cb ;current key pressed
  332. 4310 cmp #64 ;64=no key
  333. 4320 beq (NULL)on ;no key, nothing to do
  334. 4330 cmp #60 ;"space bar?
  335. 4340 bne [203][145] ;no, so ign[176]e
  336. 4350 lda inflg ;was space bar.
  337. 4360 bne g1 ;[139] set,[146] is over
  338. 4370 wa1 lda $cb ;start the [146]
  339. 4380 cmp #64 ;[129] space bar release
  340. 4390 bne wa1 ;keep [146]ing
  341. 4400 lda #1 ;set flag [164] show
  342. 4410 sta inflg ;we're looking [129] 2nd
  343. 4420 jmp wa2 ;hit of space bar
  344. 4430 [203][145] lda inflg ;[139] flag set
  345. 4440 bne wa2 ;keep looking
  346. 4450 g1 rts  ;the [146]s over
  347. 4460 ;[172]start curs[176] blink[172]
  348. 4470 cr[145] lda #0 ;clear this byte
  349. 4480 sta $cc ;[164] start blink
  350. 4490 rts
  351. 4500 ;[172][144] curs[176] blink[172]
  352. 4510 crof lda #1 ;set byte [164]
  353. 4520 sta $cc ;[144] blink
  354. 4530 rts
  355. 4540 ;[172]2 byte binary [164] 4 byte [198]ii hex[172]
  356. 4550 makhx ldx #1 ;x set [164] [161] byte
  357. 4560 ldy #0 ;y set [164] [148] [198]ii
  358. 4570 hx3 lda hldr,x ;[161] byte(hi first)
  359. 4580 [175] #$f0 ;mask low nybble
  360. 4590 lsr  ;sh[139]t hi nybble [164] low
  361. 4600 lsr
  362. 4610 lsr
  363. 4620 lsr
  364. 4630 hx1 cmp #10 ;"=>10?
  365. 4640 bcs admor ;yes, make letter
  366. 4650 clc  ;no.number
  367. 4660 adc #48 ;add 48 for ascii
  368. 4670 hx2 sta hxadd,y ;store it
  369. 4680 iny  ;raise counter
  370. 4690 cpy #3 ;"done 3 nybbles?
  371. 4700 beq skip ;yes,do 4th
  372. 4710 bcs dun ;y[177]3.we're d[145]e
  373. 4720 cpx #0 ;"y<3.hibyte done?
  374. 4730 beq nxtbyt ;yes.do low
  375. 4740 lda hldr,x ;no.get lo nyb,hi byte
  376. 4750 hx4 and #$0f ;mask hi nybble
  377. 4760 dex  ;lower counter
  378. 4770 jmp hx1 ;make ascii
  379. 4780 admor clc  ;convert binary letter
  380. 4790 adc #55 ;to ascii by
  381. 4800 jmp hx2 ;adding 55
  382. 4810 skip lda hldr,x ;get lo byte last time
  383. 4820 jmp hx4 ;do lo nybble
  384. 4830 nxtbyt ldy #2 ;reset indices fo
  385. 4840 ldx #0 ;2nd address byte
  386. 4850 jmp hx3 ;loop again
  387. 4860 dun rts  ;return
  388. 4870 ;*print hex add.stored in hxadd*
  389. 4880 prnthx jsr makhx ;binary to hex
  390. 4890 ldx #0 ;clear index
  391. 4900 lupe cpx #4 ;do 4 numbers
  392. 4910 beq fin
  393. 4920 lda hxadd,x ;get ascii hex
  394. 4930 jsr chrout ;print it
  395. 4940 inx  ;point to next char.
  396. 4950 bne lupe ;always branch
  397. 4960 fin lda #$0d ;cr
  398. 4970 jsr chrout
  399. 4980 rts  ;return
  400. 4990 ;*program finished, clean up*
  401. 5000 exit jsr clrchn ;reset default devices
  402. 5010 lda #7 ;default value & file#
  403. 5020 sta ckbyt ;save it
  404. 5030 jsr close ;close file 7
  405. 5040 rts  ;back to basic
  406. 5050 ;*storage*
  407. 5060 hxadd .byte 0,0,0,0 ;4 bytes to hold ascii hex
  408. 5070 mtchck .byte 0,0 ;last add. to check
  409. 5080 enck .byte 0,0 ;last add. for match
  410. 5090 inflg .byte 0 ;user add. input flag
  411. 5100 ckbyt .byte $07 ;# bytes to match
  412. 5110 mtchflg .byte 0 ;new group flag
  413. 5120 hldr .byte 0,0 ;temporary storage
  414. 5130 .end
  415.